package sisdroid.client;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import android.app.Activity;
import android.content.Context;
import android.net.wifi.*;
public class WifiDiscoverer implements NetDiscoverer
{

	Activity activity;
	WifiManager manager;
	public WifiDiscoverer( Activity activity )
	{
		this.activity = activity;
		manager = (WifiManager) activity.getSystemService( Context.WIFI_SERVICE );
		manager.startScan( );
	}
	
	@Override
	public Set<sisdroid.client.model.Location> getNetIDS()
	{
		
		Set<sisdroid.client.model.Location> result = new HashSet<sisdroid.client.model.Location>();
		
		// In case scan was not successfully we just bail out with an empty array
		List<ScanResult> wifiresult = manager.getScanResults(); 
		
		// Null result means no ScanResult possible (WiFi is most likely disconnected) 
		if ( wifiresult == null ) 
		{
			for ( ScanResult sr : wifiresult )
			{
				//TODO: Should we include signal strength?
				result.add( new sisdroid.client.model.Location( "wifimac", sr.BSSID ) );
				result.add( new sisdroid.client.model.Location("wifissid", sr.SSID ) );
			}
		}
		return result;
	}

}
